<template>
	<view class="login">
	<button  data-eventsync="true" open-type="getUserProfile" @tap="denglu" style="margin-top: 40rpx;" size="mini" type="primary">抖音登录 <br>（获取用户头像、名称、openid、unionid）</button>	
	</view>
</template>

<script setup>
	// 授权获取用户头像和名称
	const denglu = () => {
	dylogin()
	uni.getUserProfile({
		force: true,
		 success(res) {
		    console.log("getUserProfile 调用成功：", res.userInfo);
		  },
		  fail(res) {
		    console.log("getUserProfile 调用失败", res);
		  },
	})
	}
	//获取用户openid、unionid、anonymous_openid、session_key
	const dylogin = () => {
	uni.login({
	  force: true,
	  success(res) {
	    console.log(`login 调用成功${res.code} ${res.anonymousCode}`);
		uniCloud.callFunction({
				name: 'login',
				data: {
					code:res.code,
					anonymousCode:res.anonymousCode
				}
			}).then(res => {
			console.log(`login`,res);
			});
	  },
	  fail(res) {
	    console.log(`login 调用失败`);
	  },
	})
	}
</script>

<style>
	.login{
		margin-top: 200rpx;
		text-align: center;
		justify-content: center;
		align-items: center;
	}
</style>